package com.atguigu.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.atguigu.base.BaseDao;
import com.atguigu.base.BaseServiceImpl;
import com.atguigu.dao.DictDao;
import com.atguigu.dao.HouseDao;
import com.atguigu.entity.Dict;
import com.atguigu.entity.House;
import com.atguigu.service.HouseService;
import com.atguigu.vo.HouseQueryVo;
import com.atguigu.vo.HouseVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lhh
 * @ClassName HouseServiceImpl
 * @date 2022/9/18 10:55
 */

@Service(interfaceClass = HouseService.class)
@Transactional
public class HouseServiceImpl extends BaseServiceImpl<House> implements HouseService {

    @Autowired
    private HouseDao houseDao;

    @Autowired
    private DictDao dictDao;

    @Override
    protected BaseDao<House> getEntityDao() {
        return houseDao;
    }

    public int publish(Long id, Integer status) {
        return houseDao.publish(id,status);
    }

    public PageInfo<HouseVo> findListPage(Integer pageNum, Integer pageSize, HouseQueryVo houseQueryVo) {

        PageHelper.startPage(pageNum,pageSize);
        Page<HouseVo> page=houseDao.findListPage(houseQueryVo);
        List<HouseVo> list = page.getResult();
        for (HouseVo houseVo : list) {
            //楼层
            String floorName = dictDao.getNameById(houseVo.getFloorId());
            houseVo.setFloorName(floorName);
            //朝向：
            String directionName = dictDao.getNameById(houseVo.getDirectionId());
            houseVo.setDirectionName(directionName);
            //户型
            String houseTypeName = dictDao.getNameById(houseVo.getHouseTypeId());
            houseVo.setHouseTypeName(houseTypeName);
        }

        return new PageInfo<HouseVo>(page);
    }
}
